import { reactive, ref } from "vue";
import {
  getRecommendSongList,
  getPrivateContent,
  getRecommendNewSongs,
  getRecommendMV,
  getPlayListCategoryDict,
} from "@/api/index";
import { SongList, BroadCastItem, HomeNewSong, MVModel } from "@/types/index";

export function useHomeRecommendSongList() {
  let songListTop = reactive<SongList[]>([]);
  let songListBottom = reactive<SongList[]>([]);

  const updateUseSong = () => {
    getRecommendSongList(8).then((res) => {
      if (res.code == 200) {
        res.result.forEach((item, index) => {
          if (index < 4) {
            songListTop.push(item);
          } else {
            songListBottom.push(item);
          }
        });
      }
    });
  };

  return { songListTop, songListBottom, updateUseSong };
}

export function useRecommendNewSongs() {
  let newSongs = ref<HomeNewSong[]>([]);

  const updateUseNewSongs = (limit?: number) => {
    getRecommendNewSongs(limit).then((res) => {
      if (res.code === 200) {
        newSongs.value = res.result;
      }
    });
  };

  return { newSongs, updateUseNewSongs };
}

export function usePrivateContent() {
  let homePrivateContent = ref<BroadCastItem[]>([]);

  getPrivateContent().then((res) => {
    if (res.code === 200) {
      homePrivateContent.value = res.result;
    }
  });

  return { homePrivateContent };
}

export function useHomeMV() {
  let MVList = ref<MVModel[]>([]);

  let UpdateMVList = () => {
    getRecommendMV().then((res) => {
      if (res.code === 200) {
        MVList.value = res.result;
      }
    });
  };

  return { MVList, UpdateMVList };
}
